package bdsender

import (
	"github.com/project-flogo/core/data/coerce"
)

// Settings activity settings
type Settings struct {
	Slots []interface{} `md:"slots"`
}

// Input acitvity input
type Input struct {
	SlotSelection int                    `md:"slotSelection"`
	Data          map[string]interface{} `md:"data" json:"data,omitempty"`
}

// ToMap convert input to plain map
func (r *Input) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"slotSelection": r.SlotSelection,
		"data":          r.Data,
	}
}

// FromMap set input from plain map
func (r *Input) FromMap(values map[string]interface{}) error {
	data, err := coerce.ToObject(values["data"])
	if err != nil {
		return err
	}
	r.Data = data

	return nil
}

// Output activity output
type Output struct {
	Data []byte `md:"data" json:"data,omitempty"`
	Err  string `md:"err"`
}

// ToMap convert output to plain map
func (r *Output) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"data": r.Data,
		"err":  r.Err,
	}
}

// FromMap set output from plain map
func (r *Output) FromMap(values map[string]interface{}) error {
	data, err := coerce.ToBytes(values["data"])
	if err != nil {
		return err
	}
	r.Data = data

	errStr, err := coerce.ToString(values["err"])
	if err != nil {
		return err
	}
	r.Err = errStr

	return nil
}
